package main

import (
	"GoForAvataAPIDemo/config"
	"GoForAvataAPIDemo/models/req"
	"GoForAvataAPIDemo/service"
	"encoding/json"
	"github.com/sirupsen/logrus"
	"github.com/spf13/pflag"
)

func main() {
	var (
		cfg = pflag.StringP("config", "c", "", "./config.yaml")
	)
	//geta("eqwer")
	if err := config.Init(*cfg); err != nil {
		panic(err)
	}

	// 创建 NFT 类别
	//nftClassCreate()
	//查询 NFT 类别
	//nftClassQuery()
	//查询 NFT 类别详情
	//nftClassDetailQuery()
	//转让 NFT 类别
	//nftClassTransfer()
	//发行 NFT
	//nftCreate()
	//转让 NFT
	//nftTransfer()
	//编辑 NFT
	//nftEdit()
	//销毁 NFT
	//nftDelete()
	//查询 NFT
	//nftQuery()
	//查询 NFT 详情
	//nftDetailQuery()
	//查询 NFT 操作记录
	nftHistoryQuery()
}

// nftClassCreate 创建 NFT 类别
func nftClassCreate() {
	param := new(req.NFTClassCreateReq)
	param.Name = "boboNFTClassTest2"
	param.Owner = "iaa12raqplxcer2lqcp0j8s9s8mq6sfyhxzkhtqtqe"
	param.OperationId = "safd23gvddaV9ewedcx4236"
	result, err := service.NFTClassesCreate(param)
	if err.Err != nil {
		logrus.Error(err.Err)
	}
	byteResultStr, _ := json.Marshal(result)
	logrus.Println(string(byteResultStr))
	byteErrStr, _ := json.Marshal(err)
	logrus.Error(string(byteErrStr))
}

// nftClassQuery 查询 NFT 类别
func nftClassQuery() {
	param := new(req.NFTClassQueryReq)
	//param.Owner = "iaa12raqplxcer2lqcp0j8s9s8mq6sfyhxzkhtqtqe"
	param.Owner = "iaa1mg0ullv2vmceqzy83dv2ts7y782tvcxvcpf90l"
	result, err := service.NFTClassesQuery(param)
	if err.Err != nil {
		logrus.Error(err.Err)
	}
	byteResultStr, _ := json.Marshal(result)
	logrus.Println(string(byteResultStr))
	byteErrStr, _ := json.Marshal(err)
	logrus.Error(string(byteErrStr))
}

// nftClassDetailQuery 查询 NFT 类别详情
func nftClassDetailQuery() {
	classId := "avata232b584c954d6ef5376c4dfade289891b1b2b987a1c1aa94a108b4a4113d11ee"
	result, err := service.NFTClassesDetailQuery(classId)
	if err.Err != nil {
		logrus.Error(err.Err)
	}
	byteResultStr, _ := json.Marshal(result)
	logrus.Println(string(byteResultStr))
	byteErrStr, _ := json.Marshal(err)
	logrus.Error(string(byteErrStr))
}

// nftClassTransfer 转让 NFT 类别
func nftClassTransfer() {
	param := new(req.NFTClassTransferReq)
	param.PathParam.ClassId = "avata232b584c954d6ef5376c4dfade289891b1b2b987a1c1aa94a108b4a4113d11ee"
	param.PathParam.Owner = "iaa12raqplxcer2lqcp0j8s9s8mq6sfyhxzkhtqtqe"
	param.RequestBody.Recipient = "iaa1mg0ullv2vmceqzy83dv2ts7y782tvcxvcpf90l"
	param.RequestBody.OperationId = "safd23gvddaV9ewedcx4238"
	result, err := service.NFTClassesTransfer(param)
	if err.Err != nil {
		logrus.Error(err.Err)
	}
	byteResultStr, _ := json.Marshal(result)
	logrus.Println(string(byteResultStr))
	byteErrStr, _ := json.Marshal(err)
	logrus.Error(string(byteErrStr))
}

//发行 NFT
func nftCreate() {
	param := new(req.NFTCreateReq)
	param.PathParam.ClassId = "avata232b584c954d6ef5376c4dfade289891b1b2b987a1c1aa94a108b4a4113d11ee"
	param.RequestBody.Name = "bobo.test.nft.02"
	param.RequestBody.OperationId = "safd23gvddaV9ewedcx4247"
	result, err := service.NFTCreate(param)
	if err.Err != nil {
		logrus.Error(err.Err)
	}
	byteResultStr, _ := json.Marshal(result)
	logrus.Println(string(byteResultStr))
	byteErrStr, _ := json.Marshal(err)
	logrus.Error(string(byteErrStr))
}

//转让 NFT
func nftTransfer() {
	param := new(req.NFTTransferReq)
	param.PathParam.ClassId = "avata232b584c954d6ef5376c4dfade289891b1b2b987a1c1aa94a108b4a4113d11ee"
	param.PathParam.Owner = "iaa1mg0ullv2vmceqzy83dv2ts7y782tvcxvcpf90l"
	param.PathParam.NftId = "avata150019a88d8f5089da056da58ebcca410a0101c47d71cff8597d906867de9c68"
	param.RequestBody.Recipient = "iaa16ykw9e8m3kr6uhejxwryt7q2glfq0ldutn8vsh"
	param.RequestBody.OperationId = "safd23gvddaV9ewedcx4241"
	result, err := service.NFTTransfer(param)
	if err.Err != nil {
		logrus.Error(err.Err)
	}
	byteResultStr, _ := json.Marshal(result)
	logrus.Println(string(byteResultStr))
	byteErrStr, _ := json.Marshal(err)
	logrus.Error(string(byteErrStr))
}

//编辑 NFT
func nftEdit() {
	param := new(req.NFTEditReq)
	param.PathParam.ClassId = "avata232b584c954d6ef5376c4dfade289891b1b2b987a1c1aa94a108b4a4113d11ee"
	param.PathParam.Owner = "iaa16ykw9e8m3kr6uhejxwryt7q2glfq0ldutn8vsh"
	param.PathParam.NftId = "avata150019a88d8f5089da056da58ebcca410a0101c47d71cff8597d906867de9c68"
	param.RequestBody.Name = "ntf.name.edit.01"
	param.RequestBody.OperationId = "safd23gvddaV9ewedcx4245"
	result, err := service.NFTEdit(param)
	if err.Err != nil {
		logrus.Error(err.Err)
	}
	byteResultStr, _ := json.Marshal(result)
	logrus.Println(string(byteResultStr))
	byteErrStr, _ := json.Marshal(err)
	logrus.Error(string(byteErrStr))
}

//销毁 NFT
func nftDelete() {
	param := new(req.NFTDeleteReq)
	param.PathParam.ClassId = "avata232b584c954d6ef5376c4dfade289891b1b2b987a1c1aa94a108b4a4113d11ee"
	param.PathParam.Owner = "iaa16ykw9e8m3kr6uhejxwryt7q2glfq0ldutn8vsh"
	param.PathParam.NftId = "avata150019a88d8f5089da056da58ebcca410a0101c47d71cff8597d906867de9c68"
	param.RequestBody.OperationId = "safd23gvddaV9ewedcx4246"
	result, err := service.NFTDelete(param)
	if err.Err != nil {
		logrus.Error(err.Err)
	}
	byteResultStr, _ := json.Marshal(result)
	logrus.Println(string(byteResultStr))
	byteErrStr, _ := json.Marshal(err)
	logrus.Error(string(byteErrStr))
}

// nftQuery 查询 NFT
func nftQuery() {
	param := new(req.NFTQueryReq)
	param.Id = "avata150019a88d8f5089da056da58ebcca410a0101c47d71cff8597d906867de9c68"
	result, err := service.NFTQuery(param)
	if err.Err != nil {
		logrus.Error(err.Err)
	}
	byteResultStr, _ := json.Marshal(result)
	logrus.Println(string(byteResultStr))
	byteErrStr, _ := json.Marshal(err)
	logrus.Error(string(byteErrStr))
}

func nftDetailQuery() {
	classId := "avata232b584c954d6ef5376c4dfade289891b1b2b987a1c1aa94a108b4a4113d11ee"
	nftId := "avatad31537652834dfcca0cba9d8660c72669873b871b58e0d98dc2834fbf6d6ab50"
	result, err := service.NFTDetailQuery(classId, nftId)
	if err.Err != nil {
		logrus.Error(err.Err)
	}
	byteResultStr, _ := json.Marshal(result)
	logrus.Println(string(byteResultStr))
	byteErrStr, _ := json.Marshal(err)
	logrus.Error(string(byteErrStr))
}

func nftHistoryQuery() {
	param := new(req.NFTHistoryQueryReq)
	param.PathParam.ClassId = "avata232b584c954d6ef5376c4dfade289891b1b2b987a1c1aa94a108b4a4113d11ee"
	param.PathParam.NftId = "avata150019a88d8f5089da056da58ebcca410a0101c47d71cff8597d906867de9c68"
	param.RequestBody.SortBy = "DATE_ASC"
	result, err := service.NFTHistoryQuery(param)
	if err.Err != nil {
		logrus.Error(err.Err)
	}
	byteResultStr, _ := json.Marshal(result)
	logrus.Println(string(byteResultStr))
	byteErrStr, _ := json.Marshal(err)
	logrus.Error(string(byteErrStr))
}
